package com.tianruan.dc.modules.sys.user.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tianruan.dc.modules.sys.user.entity.db.PermissionDO;
import com.tianruan.dc.modules.sys.user.entity.dto.PermissionDTO;
import com.tianruan.dc.modules.sys.user.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/sys/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @GetMapping
    public ResponseEntity pagePermission(Page page, PermissionDTO permissionDTO){
        return ResponseEntity.ok(permissionService.pagePermission(page,permissionDTO));
    }

    @GetMapping("/{id}")
    public ResponseEntity getPermission(@PathVariable("id")Integer id){
        return ResponseEntity.ok(permissionService.getById(id));
    }

    @PostMapping
    public ResponseEntity insertPermission(@RequestBody PermissionDO permission){
        return ResponseEntity.ok(permissionService.insertPermission(permission));
    }

    @PutMapping("/{id}")
    public ResponseEntity updatePermission(@PathVariable("id")String id,
                                           @RequestBody PermissionDO permissionDO){
        permissionDO.setId(id);
        return ResponseEntity.ok(permissionService.updateById(permissionDO));
    }
}
